Page({
  data: {
    active: 0,
    currentTab: 0,
    image_sp:[]
  },
  onLoad: function () {

    var that = this;
    const  Arr=['yule','xinwen','qiche','tiyu','guonei','guoji','junshi','keji','caijing','jiankang']
    wx.request({
      url: 'http://v.juhe.cn/toutiao/index',
      method: 'GET', 
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        key:'b0f36a5a0777c6d4d6b180b2f4b34b78',
        // key:'2fb87d78c65629cebab75b13ce6429ff',
        
        type:Arr[that.data.currentTab],
        page:3,
        page_size:30,
        is_filter:1
      },
      success: function (res) {
        console.log(that.data.currentTab);
        console.log(res.data)
        const arr = res.data.result.data.filter(item => item.thumbnail_pic_s !== "");
        that.setData({
          image_sp:arr
        })
         
      },
      fail: function () {
        wx.showToast({
          title: "网络连接失败",
          duration: 3000
        })

      },
    })
  },
  switchNav: function (e) {
    var page = this;
    var id = e.target.id;
    if (this.data.currentTab == id) {
      return false;
    } else {
      page.setData({
        currentTab: id
      });
    }
    page.setData({
      active: id
    });
    page.onLoad()
  }
  
})